import org.springframework.stereotype.Component;
import org.springframework.web.context.request.async.DeferredResult;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

@Component
public class DeferredResultQueue {

    private static Queue<DeferredResult<Object>> deferredResultQueue = new ConcurrentLinkedQueue<DeferredResult<Object>>();

    public void save(DeferredResult<Object> deferredResult){
        deferredResultQueue.add(deferredResult);
    }

    public DeferredResult get(){
        DeferredResult<Object> deferredResult = deferredResultQueue.poll();
        return deferredResult;
    }
}
